﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARUserControls
{
	/// <summary>
	/// SARTextBox.xaml 的交互逻辑
	/// </summary>
	public partial class SARTextBox : UserControl
	{
		public SARTextBox()
		{
			this.InitializeComponent();
		}

        public string SARText
        {
            set
            {
                this.inputTxtField.Text = value;
            }
            get
            {
                return this.inputTxtField.Text;
            }
        }
		
		private string errorMessage = "";
        /// <summary>
        /// 错误消息，代替ErrorProvider的功能，如果设置""即可消除
        /// </summary>
        public string SARErrorMessage
        {
            set
            {
                if (String.IsNullOrEmpty(value))
                {
                    errorMessage = "";
                    imgError.Visibility = Visibility.Hidden;
                }
                else
                {
                    errorMessage = value;
                    imgError.Visibility = Visibility.Visible;
                    imgError.ToolTip = value;
                }
            }
            get
            {
                return errorMessage;
            }
        }

        private void UserControl_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                this.Opacity = 1;
            }
            else
            {
                this.Opacity = 0.5;
            }
        }
	}
}